<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>普通问卷</title>
  <link rel="stylesheet" href="/layui/css/layui.css">
  <!-- <link rel="stylesheet" href="/css/base.css"> -->
  <style>
    * {
      margin: 0px;
      padding: 0px;
      list-style-type: none;
      font-size: 14px;
    }

    #data-body {
      width: 700px;
      padding: 0px 30px;
      border: 1px dashed dodgerblue;
      border-top: none;
      border-bottom: none;
      margin: 30px auto;
     
    }

    .progress {
      /* background-color: rgb(207, 210, 228); */
      height: 34px;
      width: 400px;
      border: 1px solid #9bc6fd;
      position: relative;
      line-height: 34px;
      color: #348DFF;
    }

    .progress .content {
      display: flex;
      justify-content: space-between;
    }

    .progress .content .option {
      width: 300px;
      display: inline-block;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }

    .progress .content .nula {
      position: absolute;
      right: -60px;
      color: black;
    }

    .option-list {
      margin: 4px 0px;
    }

    .progress .bj {
      position: absolute;
      top: 0px;
      left: 0px;
      width: 50%;
      height: 100%;
      background-color: #D2E6FF;
      z-index: -1;
    }

    .progress span:first {
      margin-left: 6px;
    }

    .progress span:last-child {
      margin-right: 6px;
    }

    .title {
      margin-left: 20px;
      font-size: 14px;

    }

    .questions-list div:nth-child(1) {
      color: #4A4641;
      font-size: 13px;
      padding: 4px;
    }

    .questions-list {
      margin-top: 20px;
    }
  </style>
  <style>
    .text-list{
      margin-top: 10px;
      border: 1px solid darkseagreen;
    }
    .text-list li{
      height: 16px;
      background-color: #D2E6FF;
      margin: 6px;
      padding: 6px;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      color: #4A4641;
    }
  </style>
</head>

<body>

  <div id="header">

    <ul class="layui-nav" lay-bar="disabled">
      <li class="layui-nav-item" lay-unselect="" style="color: #CFCEDC;font-size: 18px;">
        <i><img src="/img/navimg.png" alt=""></i>问卷调查系统
      </li>
    </ul>
  </div>

  <div id="data-body">
    <ul>
      {% for item in resultArr %}
      <li class="questions-list">
        <div>
          <span>{{item.id}}、{{item.optionType}}</span>（共<span class="sum">{{item.writeCount}}</span>人填写）
        </div>
        <div class="title">{{item.title}}</div>
        {% if item.optionType==='文本' %}
        <div class="text-list">
          <ul>
            {% for tx in item.texts %}
            <li>{{tx}}</li>
            {% endfor %}
          </ul>
        </div>
        {% endif %}
        <div>
          <ul class="1">
            {% for item2 in item.childOptions %}
            <li class="option-list">
              <div class="progress">
                <div class="content">
                  <span class="option">{{item2.title}}</span><span class="percentage">{{item2.proportion}}</span>
                  <div class="nula"><span class="num">{{ item2.takeCount }}</span>人</div>
                </div>
                <div class="bj"></div>
              </div>
            </li>
            {% endfor %}
          </ul>
        </div>
      </li>
      {% endfor %}
    </ul>
  </div>


  <script src="/js/jquery-3.6.0.min.js"></script>
  <script src="/layui/layui.js"></script>
  <script>

    $('.questions-list').each((i, em) => {

      $(em).find('.option-list ').each((i, elem) => {
        console.log(elem);
        let width = $(elem).find('.num').text() / $(em).find('.sum').text()
        console.log(width);
        $(elem).find('.bj').css({
          width: `${(width * 100.0).toFixed(1)}%`
        })
        $(elem).find('.percentage').text(`${(width * 100.0).toFixed(1)}%`)
      })
    })

  </script>
</body>

</html>